from datetime import datetime
from django.db import models
from django.conf import settings
import mptt
from multilingual.translation import TranslationModel
from multilingual.manager import MultilingualManager
   
class Tree(models.Model):
    slug    = models.SlugField()
    image   = models.ImageField(upload_to = settings.UPLOADS_DIR+'/core/tree', blank=True, null=True)    
    parent  = models.ForeignKey('self', null=True, blank=True)
    link    = models.BooleanField(default = True)
    created = models.DateTimeField(default = datetime.now)
    updated = models.DateTimeField(default = datetime.now)
    active  = models.BooleanField(default = True)
        
    class Translation(TranslationModel):
        name = models.CharField(max_length=255)
     
    class Meta:
        ordering = ['tree_id', 'lft']
    
    def __unicode__(self):
        # note that you can use name and description fields as usual
        try:
            return u"%s" % (self.name)
        except:
            return u"-not-available-"

mptt.register(Tree, order_insertion_by=['slug'])